# Numpy数组的使用
# 数组的创建
import numpy as np
# 创建一维数组
n = np.arange(0, 10, 1, dtype=int)
print(n)
"""创建随机整数的多维数组"""
# 单个随机数
num = np.random.randint(low=1, high=100, size=20, dtype=int)
print(f"num = {num}")
# 数组
num1 = np.random.randint(low=1, high=100, size=(2, 3), dtype=int)
print(f"num1 = {num1}")
# 随机标准正态分布的多维数组
num2 = np.random.randn(3, 4, 5)
print(f"num2 = {num2}")
# 创建服从正态分布的多维数组
num3 = np.random.normal(loc=1, scale=3, size=3) # loc是均值, scale是标准差, size是数组的形状
print(f"num3 = {num3}")
# 创建一个元素为0~1(左闭右开)的多维数组
"""1"""
num4 = np.random.random(size=(2,3))
print(f"num4 = {num4}")
"""2"""
num5 = np.random.rand(2)
num0 = np.random.rand(2, 3)
print(f"num5 = {num5}")
print(f"num0 = {num0}")

"""ndarray的属性"""
print(f"num0.ndim={num0.ndim}")
print(f"num0.shape = {num0.shape}")
print(f"num0.size = {num0.size}")
print(f"num0.dtype = {num0.dtype}")

# 索引
i = [1, 2, 3, 4, 5]
n = np.array(i)
print("--------一维数组索引---------\n")
print(n[0])
number = np.random.randint(0,20,(7,5))
print(f"number = \n{number}")
print("-------- 二维数组索引 ---------\n")
print(f"number[0] = \n{number[0]}\n")
# 切片
print("----- 一维数组切片 -----\n")
print(n[:3])
print("\n")
print(n[::-1])
print("----- 二维数组切片 -----\n")
"""连续取多行"""
print(number[2:3])
print("\n")
"""间断取多行"""
print(number[[0, 2, 3]])
print("\n")

"""取一列"""
print(number[:, 0])
print("\n")
print("取连续的列\n")
print(number[:, [2, 3]])
